home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
BARNET
/
COMPILER
/
SATHER
/
!Sather
/
Library
/
Containrs
/
sa
/
set
< prev
next >
Wrap
Text File
|
1996-04-09
|
6KB
|
145 lines
---------------------------> Sather 1.1 source file <--------------------------
-- Author of H_SET, old abstraction: Holger Klawitter
-- Author: Benedict Gomes <gomes@icsi.berkeley.edu>
-- Copyright (C) 1995, International Computer Science Institute
-- COPYRIGHT NOTICE: This code is provided WITHOUT ANY WARRANTY
-- and is subject to the terms of the SATHER LIBRARY GENERAL PUBLIC
-- LICENSE contained in the file: Sather/Doc/License of the
-- Sather distribution. The license is also available from ICSI,
-- 1947 Center St., Suite 600, Berkeley CA 94704, USA.
-------------------------------------------------------------------
-- SET{E} :Currently aliased to H_SET{E}
-- $RO_SET{E} :Abstract read-only sets
-- $SET{E} :Abstract sets
-- RO_SET_INCL{E} :Partial class for read-only sets
-- SET_INCL{E} :Partial class for general sets
-- H_SET{E} :Concrete set (holger).
--------------------------------------------------------------------------
abstract class $RO_SET{E} < $CONTAINER{E}, $STR is
-- A read-only set abstraction. No modifying operations are permitted.
-- The abstraction consists essential kernel functions (has and elt!) and
-- a secondary set of useful operations which are defined by RO_SET_INCL
-- in terms of the kernel functions.
-- A particular set implementation will normally include RO_SET_INCL
-- and define the kernel operations as well as any of the other operations
-- that it can perform in a more efficient manner.
-- The conventional set operations such as union and intersection
-- are provided for convenience, but can be easily and more flexibly
-- achieved (with control over exactly what type of set is created)
-- using set views:
-- a_union_b ::= #SET{E}(a.union_view(b);
-- Usage:
-- See SET{T}
is_empty: BOOL;
-- Returns 'true' if there is no element in the set.
as_array: ARRAY{E};
-- Return the elements of the set in an array.
copy: SAME;
-- Return a copy of the current set.
-- ------ Basic Operations ----------------
union(a: $RO_SET{E}): $RO_SET{E};
-- Return a set that is the union of "self" and "a"
diff(a: $RO_SET{E}): $RO_SET{E};
-- Return a set that is the difference of "self" and "a"
-- i.e. contains all elements of self except those in "a"
intersection(a: $RO_SET{E}): $RO_SET{E};
-- Return a set that is the intersection of "self" and "a"
sym_diff(a: $RO_SET{E}): $RO_SET{E};
-- Return a set that contains all elements that are in either
-- "self" or "a", but not in both
union_view(a: $RO_SET{E}): $RO_SET{E};
-- The resulting set behaves as the union of self and "a".
-- It is a view and changes as the original sets change
diff_view(a: $RO_SET{E}): $RO_SET{E};
-- The resulting set behaves as the difference between self and "a".
-- It is a view and changes as the original sets change
intersection_view(a: $RO_SET{E}): $RO_SET{E};
-- The resulting set behaves as the intersection between self and "a".
-- It is a view and changes as the original sets change
sym_diff_view(a: $RO_SET{E}): $RO_SET{E};
-- The resulting set behaves as the symmetric difference bet self and "a".
-- It is a view and changes as the original sets change
is_subset_of(b: $RO_SET{E}): BOOL;
-- Return true if self is a subset of "b"
-- Is defined by a.difference(b) = NULL
equals(s: $RO_SET{E}): BOOL;
-- Returns true if "s" and self contain the same elements, based on
-- whatever element equality is used by this set.
end;
--------------------------------------------------------------------------
abstract class $SET{E} < $RO_SET{E} is
-- A set with reference semantics, that may be modified by
-- inserting and deleting elements
-- Usage:
-- See class SET{E}
insert(e:E);
-- Inserts the element 'e' into the set. Do nothing if "e" is present
delete(e: E);
-- Deletes the element equal to 'e' from the set
has(e:E): BOOL;
-- Returns 'true' if 'e' is in the set.
elt!: E;
-- Yields all elements of the set in arbitrary order
copy: SAME;
-- Return a copy of the current set.
clear;
-- Delete all elements
copy_from(s: $CONTAINER{E});
union(a: $RO_SET{E}): $SET{E};
-- Return a set that is the union of "self" and "a"
diff(a: $RO_SET{E}): $SET{E};
-- Return a set that is the difference of "self" and "a"
-- i.e. contains all elements of self except those in "a"
intersection(a: $RO_SET{E}): $SET{E};
-- Return a set that is the intersection of "self" and "a"
sym_diff(a: $RO_SET{E}): $SET{E};
-- Return a set that contains all elements that are in either
-- "self" or "a", but not in both
-- The following operations actually modify "self", transforming it
-- into the desired result.
to_union(a: $SET{E});
-- Transform self into the union of self and a consisting
-- of elements present in either self or a
to_intersection(a: $SET{E});
-- Transform self into the intersection of self and a,
-- consisting of only those elements present in self and a
to_diff(a: $SET{E});
-- Transform self into the difference between self and a,
-- elements present in self but not in a
to_sym_diff(a: $SET{E});
-- Transform self to contain only elements present in self or a, but
-- not in both
end; -- $SET{E}
--------------------------------------------------------------------------